//
//  CRTabBarViewController.m
//  CRChatRoom
//
//  Created by CuiFengshuai on 15/11/17.
//  Copyright © 2015年 SecondGroup. All rights reserved.
//

#import "CRTabBarViewController.h"
#import "CRTabBar.h"
#import "CRContactsController.h"
#import "CRDiscoverController.h"
#import "CRMessageController.h"
#import "CRNavigationController.h"
#import "CRSpaceViewController.h"
@interface CRTabBarViewController ()

@property (nonatomic, weak) CRTabBar *NewTabBar;

@end

@implementation CRTabBarViewController

#pragma mark >>>> 系统方法
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // 自定义控件初始化
    [self setupSubViews];
    
}

#pragma mark >>>> 初始化方法
/**
 *  自定义控件初始化
 */
- (void)setupSubViews {
    
//    CRMessageController *messageVC = [[CRMessageController alloc] init];
//    //    messageVC.view.backgroundColor = CRRandomcolor;
//    [self addChildViewController:messageVC title:@"消息" image:@"ic_nav_3_normal" selectedImage:@"ic_nav_3_active"];
    
    CRContactsController *contactVC = [[CRContactsController alloc] init];
//    contactVC.view.backgroundColor = CRRandomcolor;
    [self addChildViewController:contactVC title:@"联系人" image:@"ic_nav_4_normal" selectedImage:@"ic_nav_4_active"];
    
    CRDiscoverController *discoverVC = [[CRDiscoverController alloc] init];
//    discoverVC.view.backgroundColor = CRRandomcolor;
    [self addChildViewController:discoverVC title:@"发现" image:@"ic_nav_2_normal" selectedImage:@"ic_nav_2_active"];
    
    CRSpaceViewController *spaceVC = [[CRSpaceViewController alloc] init];
    //    profileVC.view.backgroundColor = CRRandomcolor;
    [self addChildViewController:spaceVC title:@"动态" image:@"ic_nav_1_normal" selectedImage:@"ic_nav_1_active"];
}
#pragma mark >>>> 其他方法
- (void)addChildViewController:(UIViewController *)childController title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectdeImage {
    // 设置子控制器文字
    childController.title = title;
    
    // 设置子控制器的文字样式
    [childController.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithWhite:0.502 alpha:1.000]} forState:UIControlStateNormal];
    [childController.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRed:0.108 green:0.511 blue:1.000 alpha:1.000]} forState:UIControlStateSelected];
    
    // 设置子控制器图片
    childController.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childController.tabBarItem.selectedImage = [[UIImage imageNamed:selectdeImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    // 包装成 navigationController
    CRNavigationController *naVC = [[CRNavigationController alloc] initWithRootViewController:childController];
    
    // 添加为子控制器
    [self addChildViewController:naVC];
}

#pragma mark >>>> 监听事件


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
